/*
 *
 *  oFono - Open Source Telephony
 *
 *  Copyright (C) 2009-2010  Nokia Corporation and/or its subsidiary(-ies).
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>

#include <glib.h>

#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/log.h>
#include <ofono/modem.h>
#include <ofono/sim.h>

#include "debug.h"

#define COMMON_MESSAGE	0xF0

#define _(X) case X: return #X

const char *pn_resource_name(int value)
{
	switch (value) {
		_(PN_NETWORK);
		_(PN_MODEM_NETWORK);
		_(PN_PHONE_INFO);
		_(PN_MODEM_INFO);
		_(PN_EPOC_INFO);
		_(PN_SS);
		_(PN_CALL);
		_(PN_MODEM_CALL);
		_(PN_SMS);
		_(PN_SIM);
		_(PN_SECURITY);
		_(PN_MTC);
		_(PN_MODEM_MCE);
		_(PN_GSS);
		_(PN_GPDS);
		_(PN_WRAN);
		_(PN_UICC);
	}
	return "PN_<UNKNOWN>";
}

const char *ss_message_id_name(enum ss_message_id value)
{
	switch (value) {
		_(SS_SERVICE_REQ);
		_(SS_SERVICE_COMPLETED_RESP);
		_(SS_SERVICE_FAILED_RESP);
		_(SS_SERVICE_NOT_SUPPORTED_RESP);
		_(SS_GSM_USSD_SEND_REQ);
		_(SS_GSM_USSD_SEND_RESP);
		_(SS_GSM_USSD_RECEIVE_IND);
		_(SS_STATUS_IND);
		_(SS_SERVICE_COMPLETED_IND);
	}
	return "SS_<UNKNOWN>";
}

const char *ss_ussd_type_name(enum ss_ussd_type value)
{
	switch (value) {
		_(SS_GSM_USSD_MT_REPLY);
		_(SS_GSM_USSD_COMMAND);
		_(SS_GSM_USSD_REQUEST);
		_(SS_GSM_USSD_NOTIFY);
		_(SS_GSM_USSD_END);
	}
	return "SS_<UNKNOWN>";
}


const char *ss_subblock_name(enum ss_subblock value)
{
	switch (value) {
		_(SS_FORWARDING);
		_(SS_STATUS_RESULT);
		_(SS_GSM_PASSWORD);
		_(SS_GSM_FORWARDING_INFO);
		_(SS_GSM_FORWARDING_FEATURE);
		_(SS_GSM_DATA);
		_(SS_GSM_BSC_INFO);
		_(SS_GSM_GENERIC_SERVICE_INFO);
		_(SS_GSM_CLIR_INFO);
		_(SS_GSM_PASSWORD_INFO);
		_(SS_GSM_INDICATE_PASSWORD_ERROR);
		_(SS_GSM_INDICATE_ERROR);
		_(SS_GSM_ADDITIONAL_INFO);
		_(SS_GSM_BARRING_INFO);
		_(SS_GSM_BARRING_FEATURE);
		_(SS_GSM_USSD_STRING);
	}
	return "SS_<UNKNOWN>";
}

const char *mtc_isi_cause_name(enum mtc_isi_cause value)
{
	switch (value) {
		_(MTC_OK);
		_(MTC_FAIL);
		_(MTC_NOT_ALLOWED);
		_(MTC_STATE_TRANSITION_GOING_ON);
		_(MTC_ALREADY_ACTIVE);
		_(MTC_SERVICE_DISABLED);
		_(MTC_NOT_READY_YET);
		_(MTC_NOT_SUPPORTED);
		_(MTC_TRANSITION_ONGOING);
		_(MTC_RESET_REQUIRED);
	}
	return "MTC_<UNKNOWN>";
}

const char *mtc_message_id_name(enum mtc_message_id value)
{
	switch (value) {
		_(MTC_STATE_REQ);
		_(MTC_STATE_QUERY_REQ);
		_(MTC_POWER_OFF_REQ);
		_(MTC_POWER_ON_REQ);
		_(MTC_STARTUP_SYNQ_REQ);
		_(MTC_SHUTDOWN_SYNC_REQ);
		_(MTC_STATE_RESP);
		_(MTC_STATE_QUERY_RESP);
		_(MTC_POWER_OFF_RESP);
		_(MTC_POWER_ON_RESP);
		_(MTC_STARTUP_SYNQ_RESP);
		_(MTC_SHUTDOWN_SYNC_RESP);
		_(MTC_STATE_INFO_IND);
	}
	return "MTC_<UNKNOWN>";
}

const char *mtc_modem_state_name(enum mtc_modem_state value)
{
	switch (value) {
		_(MTC_POWER_OFF);
		_(MTC_NORMAL);
		_(MTC_CHARGING);
		_(MTC_ALARM);
		_(MTC_TEST);
		_(MTC_LOCAL);
		_(MTC_WARRANTY);
		_(MTC_RELIABILITY);
		_(MTC_SELFTEST_FAIL);
		_(MTC_SWDL);
		_(MTC_RF_INACTIVE);
		_(MTC_ID_WRITE);
		_(MTC_DISCHARGING);
		_(MTC_DISK_WIPE);
		_(MTC_SW_RESET);
		_(MTC_CMT_ONLY_MODE);
		_(MTC_STATE_NONE);
	}
	return "MTC_<UNKNOWN>";
}

const char *mce_message_id_name(enum mce_message_id value)
{
	switch (value) {
		_(MCE_MODEM_STATE_IND);
		_(MCE_MODEM_STATE_QUERY_REQ);
		_(MCE_MODEM_STATE_QUERY_RESP);
		_(MCE_RF_STATE_REQ);
		_(MCE_RF_STATE_RESP);
		_(MCE_RF_STATE_IND);
		_(MCE_RF_STATE_QUERY_REQ);
		_(MCE_RF_STATE_QUERY_RESP);
		_(MCE_POWER_OFF_REQ);
		_(MCE_POWER_OFF_RESP);
	}
	return "MCE_<UNKNOWN>";
}

const char *mce_modem_state_name(enum mce_modem_state value)
{
	switch (value) {
		_(MCE_NORMAL);
		_(MCE_LOCAL);
		_(MCE_SW_RESET);
		_(MCE_POWER_OFF);
	}
	return "MCE_<UNKNOWN>";
}

const char *mce_status_info(enum mce_status_info value)
{
	switch (value) {
		_(MCE_OK);
		_(MCE_FAIL);
		_(MCE_ALREADY_ACTIVE);
		_(MCE_TRANSITION_ONGOING);
	}
	return "MCE_<UNKNOWN>";
}

const char *mce_rf_state_name(enum mce_rf_state value)
{
	switch (value) {
		_(MCE_RF_OFF);
		_(MCE_RF_ON);
	}
	return "MCE_RF<UNKNOWN>";
}

const char *uicc_service_type_name(uint8_t value)
{
	switch (value) {
		_(UICC_APPL_LIST);
		_(UICC_APPL_HOST_ACTIVATE);
		/*_(UICC_APPL_DEACTIVATE);*/
		_(UICC_APPL_START_UP_COMPLETE);
		/*_(UICC_SHUT_DOWN_INITIATED);*/
		_(UICC_APPL_SHUT_DOWN_INITIATED);
		_(UICC_APPL_STATUS_GET);
		_(UICC_APPL_HOST_DEACTIVATE);
		_(UICC_PIN_VERIFY);
		_(UICC_PIN_UNBLOCK);
		_(UICC_PIN_DISABLE);
		_(UICC_PIN_ENABLE);
		_(UICC_PIN_CHANGE);
		_(UICC_PIN_SUBSTITUTE);
		_(UICC_PIN_INFO);
		_(UICC_PIN_PROMPT_VERIFY);
		_(UICC_APPL_READ_TRANSPARENT);
		_(UICC_APPL_UPDATE_TRANSPARENT);
		_(UICC_APPL_READ_LINEAR_FIXED);
		_(UICC_APPL_UPDATE_LINEAR_FIXED);
		_(UICC_APPL_FILE_INFO);
		_(UICC_APPL_APDU_SEND);
		_(UICC_APPL_CLEAR_CACHE);
		_(UICC_APPL_SESSION_START);
		_(UICC_APPL_SESSION_END);
		_(UICC_APPL_READ_CYCLIC);
		_(UICC_APPL_UPDATE_CYCLIC);
		/*_(UICC_APPL_CACHE_UPDATED);*/
		_(UICC_CONNECT);
		_(UICC_DISCONNECT);
		_(UICC_RECONNECT);
		_(UICC_CAT_ENABLE);
		_(UICC_CAT_DISABLE);
		_(UICC_CAT_TERMINAL_PROFILE);
		_(UICC_CAT_TERMINAL_RESPONSE);
		_(UICC_CAT_ENVELOPE);
		_(UICC_CAT_POLLING_SET);
		_(UICC_CAT_REFRESH);
		_(UICC_CAT_POLL);
		_(UICC_APDU_SEND);
		_(UICC_APDU_ATR_GET);
		_(UICC_APDU_CONTROL);
		_(UICC_REFRESH_STATUS);
		_(UICC_APPL_TERMINATED);
		_(UICC_APPL_RECOVERED);
		/*_(UICC_APPL_UNAVAILABLE);*/
		/*_(UICC_APPL_SHUT_DOWN);*/
		_(UICC_APPL_ACTIVATED);
		_(UICC_PIN_VERIFY_NEEDED);
		_(UICC_PIN_UNBLOCK_NEEDED);
		_(UICC_PIN_PERMANENTLY_BLOCKED);
		_(UICC_PIN_VERIFIED);
		_(UICC_CAT_FETCHED_CMD);
		_(UICC_CAT_NOT_SUPPORTED);
		_(UICC_CAT_REG_FAILED);
		_(UICC_CAT_REG_OK);
		_(UICC_REFRESH_PERMISSION);
		_(UICC_REFRESH_STARTING);
		_(UICC_REFRESH_CANCELLED);
		_(UICC_REFRESH_NOW);
		_(UICC_START_UP_COMPLETE);
		_(UICC_STATUS_GET);
		_(UICC_READY);
		/*_(UICC_READY_FOR_ACTIVATION);*/
		_(UICC_INITIALIZED);
		_(UICC_SHUTTING_DOWN);
		/*_(UICC_SHUT_DOWN_CONFIG);*/
		_(UICC_ERROR);
		_(UICC_CARD_DISCONNECTED);
		_(UICC_CARD_REMOVED);
		_(UICC_CARD_NOT_PRESENT);
		/*_(UICC_CARD_RESET);*/
		_(UICC_CARD_READY);
		_(UICC_CARD_STATUS_GET);
		_(UICC_CARD_REJECTED);
		_(UICC_CARD_INFO_GET);
		_(UICC_SIMLOCK_ACTIVE);
		_(UICC_APDU_SAP_ACTIVATE);
		_(UICC_APDU_SAP_DEACTIVATE);
		_(UICC_APDU_SAP_ATR_GET);
		_(UICC_APDU_SAP_COLD_RESET);
		_(UICC_APDU_SAP_WARM_RESET);
		_(UICC_APDU_SAP_APDU_SEND);
		_(UICC_APDU_SAP_RECOVERY);
		_(UICC_APDU_SAP_CONFIG_GET);
		_(UICC_PWR_CTRL_ENABLE);
		_(UICC_PWR_CTRL_DISABLE);
		_(UICC_PWR_CTRL_WAIT);
		_(UICC_PWR_CTRL_PROCEED);
		_(UICC_PWR_CTRL_PERMISSION);
	}
	return "UICC_SERVICE_<UNKNOWN>";
}

const char *uicc_details_name(uint8_t value)
{

	switch (value) {
		/* Used when status differs from UICC_STATUS_FAIL */
		_(UICC_NO_DETAILS);
		/* Request was sent with one or more invalid parameter */
		_(UICC_INVALID_PARAMETERS);
		/* The file wasn't found */
		_(UICC_FILE_NOT_FOUND);
		/* User does not have the required priviledges for this */
		_(UICC_SECURITY_CONDITIONS_NOT_SATISFIED);
		/* Application can not be activated due to already active app */
		_(UICC_APPL_CONFLICT);
		/* Card Communication error */
		_(UICC_CARD_ERROR);
		/* Operation not supported */
		_(UICC_SERVICE_NOT_SUPPORTED);
		/* Session expired  */
		_(UICC_SESSION_EXPIRED);
	}
	return "UICC_STATUS<UNKNOWN>";
}

const char *uicc_message_id_name(enum uicc_message_id value)
{
	switch (value) {
		_(UICC_REQ);
		_(UICC_RESP);
		_(UICC_IND);
		_(UICC_CARD_REQ);
		_(UICC_CARD_RESP);
		_(UICC_CARD_IND);
		_(UICC_APPLICATION_REQ);
		_(UICC_APPLICATION_RESP);
		_(UICC_APPLICATION_IND);
		_(UICC_PIN_REQ);
		_(UICC_PIN_RESP);
		_(UICC_PIN_IND);
		_(UICC_APPL_CMD_REQ);
		_(UICC_APPL_CMD_RESP);
		_(UICC_APPL_CMD_IND);
		_(UICC_CONNECTOR_REQ);
		_(UICC_CONNECTOR_RESP);
		_(UICC_CAT_REQ);
		_(UICC_CAT_RESP);
		_(UICC_CAT_IND);
		_(UICC_APDU_REQ);
		_(UICC_APDU_RESP);
		_(UICC_APDU_RESET_IND);
		_(UICC_REFRESH_REQ);
		_(UICC_REFRESH_RESP);
		_(UICC_REFRESH_IND);
		_(UICC_SIMLOCK_REQ);
		_(UICC_SIMLOCK_RESP);
		_(UICC_APDU_SAP_REQ);
		_(UICC_APDU_SAP_RESP);
		_(UICC_APDU_SAP_IND);
		_(UICC_PWR_CTRL_REQ);
		_(UICC_PWR_CTRL_RESP);
		_(UICC_PWR_CTRL_IND);
		_(UICC_CARD_READER_IND);
	}
	return "UICC_<UNKNOWN>";
}

const char *uicc_status_name(uint8_t value)
{
	switch (value) {
		/* Request performed successfully */
		_(UICC_STATUS_OK);
		/* Error in performing the command */
		_(UICC_STATUS_FAIL);
		/* Status is Unknown */
		_(UICC_STATUS_UNKNOWN);
		/* Server is not ready */
		_(UICC_STATUS_NOT_READY);
		/* Server start up is completed */
		_(UICC_STATUS_START_UP_COMPLETED);
		/* Server is shutting down */
		_(UICC_STATUS_SHUTTING_DOWN);
		/* Smart card is not ready */
		_(UICC_STATUS_CARD_NOT_READY);
		/* Smart card is ready */
		_(UICC_STATUS_CARD_READY);
		/* Smart card is disconnected */
		_(UICC_STATUS_CARD_DISCONNECTED);
		/* Smart card is not present */
		_(UICC_STATUS_CARD_NOT_PRESENT);
		/* Smart card has been rejected */
		_(UICC_STATUS_CARD_REJECTED);
		/* Application is active */
		_(UICC_STATUS_APPL_ACTIVE);
		/* Application is not active */
		_(UICC_STATUS_APPL_NOT_ACTIVE);
		/* PIN verification used */
		_(UICC_STATUS_PIN_ENABLED);
		/* PIN verification not used */
		_(UICC_STATUS_PIN_DISABLED);
	}
	return "UICC_STATUS<UNKNOWN>";
}

const char *uicc_subblock_name(uint8_t value)
{
	switch (value) {
		_(UICC_SB_SHUT_DOWN_CONFIG);
		_(UICC_SB_CARD_STATUS);
		_(UICC_SB_CARD_INFO);
		_(UICC_SB_CARD_REJECT_CAUSE);
		_(UICC_SB_CLIENT);
		_(UICC_SB_APPL_DATA_OBJECT);
		_(UICC_SB_APPLICATION);
		_(UICC_SB_APPL_INFO);
		_(UICC_SB_APPL_STATUS);
		_(UICC_SB_FCP);
		_(UICC_SB_FCI);
		_(UICC_SB_CHV);
		_(UICC_SB_PIN);
		_(UICC_SB_PIN_REF);
		_(UICC_SB_PUK);
		_(UICC_SB_PIN_SUBST);
		_(UICC_SB_PIN_INFO);
		_(UICC_SB_APPL_PATH);
		_(UICC_SB_SESSION);
		_(UICC_SB_FILE_DATA);
		_(UICC_SB_APDU);
		_(UICC_SB_TRANSPARENT_READ);
		_(UICC_SB_TRANSPARENT_UPDATE);
		_(UICC_SB_TRANSPARENT);
		_(UICC_SB_LINEAR_FIXED);
		_(UICC_SB_CYCLIC);
		_(UICC_SB_TERMINAL_PROFILE);
		_(UICC_SB_TERMINAL_RESPONSE);
		_(UICC_SB_ENVELOPE);
		_(UICC_SB_POLLING_SET);
		_(UICC_SB_REFRESH);
		_(UICC_SB_AID);
		_(UICC_SB_REFRESH_RESULT);
		_(UICC_SB_APDU_ACTIONS);
		_(UICC_SB_OBJECT_ID);
		_(UICC_SB_STATUS_WORD);
		_(UICC_SB_APDU_SAP_INFO);
		_(UICC_SB_ACCESS_MODE);
		_(UICC_SB_RESP_INFO);
		_(UICC_SB_APDU_SAP_CONFIG);
	}
	return "UICC_<UNKNOWN>";
}

const char *sms_isi_cause_name(enum sms_isi_cause value)
{
	switch (value) {
		_(SMS_OK);
		_(SMS_ERR_ROUTING_RELEASED);
		_(SMS_ERR_INVALID_PARAMETER);
		_(SMS_ERR_DEVICE_FAILURE);
		_(SMS_ERR_PP_RESERVED);
		_(SMS_ERR_ROUTE_NOT_AVAILABLE);
		_(SMS_ERR_ROUTE_NOT_ALLOWED);
		_(SMS_ERR_SERVICE_RESERVED);
		_(SMS_ERR_INVALID_LOCATION);
		_(SMS_ERR_NO_SIM);
		_(SMS_ERR_SIM_NOT_READY);
		_(SMS_ERR_NO_NETW_RESPONSE);
		_(SMS_ERR_DEST_ADDR_FDN_RESTRICTED);
		_(SMS_ERR_SMSC_ADDR_FDN_RESTRICTED);
		_(SMS_ERR_RESEND_ALREADY_DONE);
		_(SMS_ERR_SMSC_ADDR_NOT_AVAILABLE);
		_(SMS_ERR_ROUTING_FAILED);
		_(SMS_ERR_CS_INACTIVE);
		_(SMS_ERR_SAT_MO_CONTROL_MODIFIED);
		_(SMS_ERR_SAT_MO_CONTROL_REJECT);
		_(SMS_ERR_TRACFONE_FAILED);
	}
	return "SMS_<UNKNOWN>";
}

const char *sms_gsm_cause_name(enum sms_gsm_cause value)
{
	switch (value) {
		_(SMS_GSM_ERR_UNASSIGNED_NUMBER);
		_(SMS_GSM_ERR_OPER_DETERMINED_BARR);
		_(SMS_GSM_ERR_CALL_BARRED);
		_(SMS_GSM_ERR_RESERVED);
		_(SMS_GSM_ERR_MSG_TRANSFER_REJ);
		_(SMS_GSM_ERR_MEMORY_CAPACITY_EXC);
		_(SMS_GSM_ERR_DEST_OUT_OF_ORDER);
		_(SMS_GSM_ERR_UNDEFINED_SUBSCRIBER);
		_(SMS_GSM_ERR_FACILITY_REJECTED);
		_(SMS_GSM_ERR_UNKNOWN_SUBSCRIBER);
		_(SMS_GSM_ERR_NETW_OUT_OF_ORDER);
		_(SMS_GSM_ERR_TEMPORARY_FAILURE);
		_(SMS_GSM_ERR_CONGESTION);
		_(SMS_GSM_ERR_RESOURCE_UNAVAILABLE);
		_(SMS_GSM_ERR_REQ_FACILITY_NOT_SUB);
		_(SMS_GSM_ERR_REQ_FACILITY_NOT_IMP);
		_(SMS_GSM_ERR_INVALID_REFERENCE);
		_(SMS_GSM_ERR_INCORRECT_MESSAGE);
		_(SMS_GSM_ERR_INVALID_MAND_INFO);
		_(SMS_GSM_ERR_INVALID_MSG_TYPE);
		_(SMS_GSM_ERR_MSG_NOT_COMP_WITH_ST);
		_(SMS_GSM_ERR_INVALID_INFO_ELEMENT);
		_(SMS_GSM_ERR_PROTOCOL_ERROR);
		_(SMS_GSM_ERR_INTERWORKING);
		_(SMS_GSM_ERR_NO_CAUSE);
		_(SMS_GSM_ERR_IMSI_UNKNOWN_HLR);
		_(SMS_GSM_ERR_ILLEGAL_MS);
		_(SMS_GSM_ERR_IMSI_UNKNOWN_VLR);
		_(SMS_GSM_ERR_IMEI_NOT_ACCEPTED);
		_(SMS_GSM_ERR_ILLEGAL_ME);
		_(SMS_GSM_ERR_PLMN_NOT_ALLOWED);
		_(SMS_GSM_ERR_LA_NOT_ALLOWED);
		_(SMS_GSM_ERR_ROAM_NOT_ALLOWED_LA);
		_(SMS_GSM_ERR_NO_SUITABLE_CELLS_LA);
		_(SMS_GSM_ERR_NETWORK_FAILURE);
		_(SMS_GSM_ERR_MAC_FAILURE);
		_(SMS_GSM_ERR_SYNC_FAILURE);
		_(SMS_GSM_ERR_LOW_LAYER_CONGESTION);
		_(SMS_GSM_ERR_AUTH_UNACCEPTABLE);
		_(SMS_GSM_ERR_SERV_OPT_NOT_SUPPORTED);
		_(SMS_GSM_ERR_SERV_OPT_NOT_SUBSCRIBED);
		_(SMS_GSM_ERR_SERV_OPT_TEMP_OUT_OF_ORDER);
		_(SMS_GSM_ERR_CALL_CANNOT_BE_IDENTIFIED);
		_(SMS_GSM_ERR_SEMANTICALLY_INCORR_MSG);
		_(SMS_GSM_ERR_LOW_LAYER_INVALID_MAND_INFO);
		_(SMS_GSM_ERR_LOW_LAYER_INVALID_MSG_TYPE);
		_(SMS_GSM_ERR_LOW_LAYER_MSG_TYPE_NOT_COMP_WITH_ST);
		_(SMS_GSM_ERR_LOW_LAYER_INVALID_INFO_ELEMENT);
		_(SMS_GSM_ERR_CONDITIONAL_IE_ERROR);
		_(SMS_GSM_ERR_LOW_LAYER_MSG_NOT_COMP_WITH_ST);
		_(SMS_GSM_ERR_CS_BARRED);
		_(SMS_GSM_ERR_LOW_LAYER_PROTOCOL_ERROR);
	}
	return "SMS_<UNKNOWN>";
}

const char *sms_message_id_name(enum sms_message_id value)
{
	switch (value) {
		_(SMS_MESSAGE_SEND_REQ);
		_(SMS_MESSAGE_SEND_RESP);
		_(SMS_PP_ROUTING_REQ);
		_(SMS_PP_ROUTING_RESP);
		_(SMS_PP_ROUTING_NTF);
		_(SMS_GSM_RECEIVED_PP_REPORT_REQ);
		_(SMS_GSM_RECEIVED_PP_REPORT_RESP);
		_(SMS_GSM_CB_ROUTING_REQ);
		_(SMS_GSM_CB_ROUTING_RESP);
		_(SMS_GSM_CB_ROUTING_NTF);
		_(SMS_MESSAGE_SEND_STATUS_IND);
		_(SMS_SETTINGS_UPDATE_REQ);
		_(SMS_SETTINGS_UPDATE_RESP);
		_(SMS_SETTINGS_READ_REQ);
		_(SMS_SETTINGS_READ_RESP);
		_(SMS_RECEIVED_MSG_REPORT_REQ);
		_(SMS_RECEIVED_MSG_REPORT_RESP);
		_(SMS_RECEIVE_MESSAGE_REQ);
		_(SMS_RECEIVE_MESSAGE_RESP);
		_(SMS_RECEIVED_MSG_IND);
	}
	return "SMS_<UNKNOWN>";
}

const char *sms_subblock_name(enum sms_subblock value)
{
	switch (value) {
		_(SMS_GSM_DELIVER);
		_(SMS_GSM_STATUS_REPORT);
		_(SMS_GSM_SUBMIT);
		_(SMS_GSM_COMMAND);
		_(SMS_GSM_DELIVER_REPORT);
		_(SMS_GSM_REPORT);
		_(SMS_GSM_ROUTING);
		_(SMS_GSM_CB_MESSAGE);
		_(SMS_GSM_TPDU);
		_(SMS_SB_TPDU);
		_(SMS_SB_ROUTE_INFO);
		_(SMS_SB_SMS_PARAMETERS);
		_(SMS_COMMON_DATA);
		_(SMS_ADDRESS);
		/* _(SMS_SB_ADDRESS); */
	}
	return "SMS_<UNKNOWN>";
}

const char *sim_isi_cause_name(enum sim_isi_cause value)
{
	switch (value) {
		_(SIM_SERV_NOT_AVAIL);
		_(SIM_SERV_OK);
		_(SIM_SERV_PIN_VERIFY_REQUIRED);
		_(SIM_SERV_PIN_REQUIRED);
		_(SIM_SERV_SIM_BLOCKED);
		_(SIM_SERV_SIM_PERMANENTLY_BLOCKED);
		_(SIM_SERV_SIM_DISCONNECTED);
		_(SIM_SERV_SIM_REJECTED);
		_(SIM_SERV_LOCK_ACTIVE);
		_(SIM_SERV_AUTOLOCK_CLOSED);
		_(SIM_SERV_AUTOLOCK_ERROR);
		_(SIM_SERV_INIT_OK);
		_(SIM_SERV_INIT_NOT_OK);
		_(SIM_SERV_WRONG_OLD_PIN);
		_(SIM_SERV_PIN_DISABLED);
		_(SIM_SERV_COMMUNICATION_ERROR);
		_(SIM_SERV_UPDATE_IMPOSSIBLE);
		_(SIM_SERV_NO_SECRET_CODE_IN_SIM);
		_(SIM_SERV_PIN_ENABLE_OK);
		_(SIM_SERV_PIN_DISABLE_OK);
		_(SIM_SERV_WRONG_UNBLOCKING_KEY);
		_(SIM_SERV_ILLEGAL_NUMBER);
		_(SIM_SERV_NOT_OK);
		_(SIM_SERV_PN_LIST_ENABLE_OK);
		_(SIM_SERV_PN_LIST_DISABLE_OK);
		_(SIM_SERV_NO_PIN);
		_(SIM_SERV_PIN_VERIFY_OK);
		_(SIM_SERV_PIN_BLOCKED);
		_(SIM_SERV_PIN_PERM_BLOCKED);
		_(SIM_SERV_DATA_NOT_AVAIL);
		_(SIM_SERV_IN_HOME_ZONE);
		_(SIM_SERV_STATE_CHANGED);
		_(SIM_SERV_INF_NBR_READ_OK);
		_(SIM_SERV_INF_NBR_READ_NOT_OK);
		_(SIM_SERV_IMSI_EQUAL);
		_(SIM_SERV_IMSI_NOT_EQUAL);
		_(SIM_SERV_INVALID_LOCATION);
		_(SIM_SERV_STA_SIM_REMOVED);
		_(SIM_SERV_SECOND_SIM_REMOVED_CS);
		_(SIM_SERV_CONNECTED_INDICATION_CS);
		_(SIM_SERV_SECOND_SIM_CONNECTED_CS);
		_(SIM_SERV_PIN_RIGHTS_LOST_IND_CS);
		_(SIM_SERV_PIN_RIGHTS_GRANTED_IND_CS);
		_(SIM_SERV_INIT_OK_CS);
		_(SIM_SERV_INIT_NOT_OK_CS);
		_(SIM_FDN_ENABLED);
		_(SIM_FDN_DISABLED);
		_(SIM_SERV_INVALID_FILE);
		_(SIM_SERV_DATA_AVAIL);
		_(SIM_SERV_ICC_EQUAL);
		_(SIM_SERV_ICC_NOT_EQUAL);
		_(SIM_SERV_SIM_NOT_INITIALISED);
		_(SIM_SERV_SERVICE_NOT_AVAIL);
		_(SIM_SERV_FDN_STATUS_ERROR);
		_(SIM_SERV_FDN_CHECK_PASSED);
		_(SIM_SERV_FDN_CHECK_FAILED);
		_(SIM_SERV_FDN_CHECK_DISABLED);
		_(SIM_SERV_FDN_CHECK_NO_FDN_SIM);
		_(SIM_STA_ISIM_AVAILEBLE_PIN_REQUIRED);
		_(SIM_STA_ISIM_AVAILEBLE);
		_(SIM_STA_USIM_AVAILEBLE);
		_(SIM_STA_SIM_AVAILEBLE);
		_(SIM_STA_ISIM_NOT_INITIALIZED);
		_(SIM_STA_IMS_READY);
		_(SIM_STA_APP_DATA_READ_OK);
		_(SIM_STA_APP_ACTIVATE_OK);
		_(SIM_STA_APP_ACTIVATE_NOT_OK);
		_(SIM_SERV_NOT_DEFINED);
		_(SIM_SERV_NOSERVICE);
		_(SIM_SERV_NOTREADY);
		_(SIM_SERV_ERROR);
		_(SIM_SERV_CIPHERING_INDICATOR_DISPLAY_REQUIRED);
		_(SIM_SERV_CIPHERING_INDICATOR_DISPLAY_NOT_REQUIRED);
		_(SIM_SERV_FILE_NOT_AVAILABLE);
	}
	return "SIM_<UNKNOWN>";
}

const char *sim_message_id_name(enum sim_message_id value)
{
	switch (value) {
		_(SIM_NETWORK_INFO_REQ);
		_(SIM_NETWORK_INFO_RESP);
		_(SIM_IMSI_REQ_READ_IMSI);
		_(SIM_IMSI_RESP_READ_IMSI);
		_(SIM_SERV_PROV_NAME_REQ);
		_(SIM_SERV_PROV_NAME_RESP);
		_(SIM_DYNAMIC_FLAGS_REQ);
		_(SIM_DYNAMIC_FLAGS_RESP);
		_(SIM_READ_FIELD_REQ);
		_(SIM_READ_FIELD_RESP);
		_(SIM_SMS_REQ);
		_(SIM_SMS_RESP);
		_(SIM_STATUS_REQ);
		_(SIM_STATUS_RESP);
		_(SIM_PB_REQ_SIM_PB_READ);
		_(SIM_PB_RESP_SIM_PB_READ);
		_(SIM_SERVER_READY_IND);
		_(SIM_IND);
	}

	return "SIM_<UNKNOWN>";
}

const char *sim_password_name(enum ofono_sim_password_type type)
{
	static const char *const passwd_name[] = {
		[OFONO_SIM_PASSWORD_NONE] = "none",
		[OFONO_SIM_PASSWORD_SIM_PIN] = "pin",
		[OFONO_SIM_PASSWORD_SIM_PUK] = "puk",
		[OFONO_SIM_PASSWORD_PHSIM_PIN] = "phone",
		[OFONO_SIM_PASSWORD_PHFSIM_PIN] = "firstphone",
		[OFONO_SIM_PASSWORD_PHFSIM_PUK] = "firstphonepuk",
		[OFONO_SIM_PASSWORD_SIM_PIN2] = "pin2",
		[OFONO_SIM_PASSWORD_SIM_PUK2] = "puk2",
		[OFONO_SIM_PASSWORD_PHNET_PIN] = "network",
		[OFONO_SIM_PASSWORD_PHNET_PUK] = "networkpuk",
		[OFONO_SIM_PASSWORD_PHNETSUB_PIN] = "netsub",
		[OFONO_SIM_PASSWORD_PHNETSUB_PUK] = "netsubpuk",
		[OFONO_SIM_PASSWORD_PHSP_PIN] = "service",
		[OFONO_SIM_PASSWORD_PHSP_PUK] = "servicepuk",
		[OFONO_SIM_PASSWORD_PHCORP_PIN] = "corp",
		[OFONO_SIM_PASSWORD_PHCORP_PUK] = "corppuk",
		[OFONO_SIM_PASSWORD_INVALID] = "invalid",
	};

	if (OFONO_SIM_PASSWORD_NONE <= (int)type &&
			type <= OFONO_SIM_PASSWORD_PHCORP_PUK)
		return passwd_name[type];
	else
		return "UNKNOWN";
}

const char *sec_message_id_name(enum sec_message_id value)
{
	switch (value) {
		_(SEC_CODE_STATE_REQ);
		_(SEC_CODE_STATE_OK_RESP);
		_(SEC_CODE_STATE_FAIL_RESP);
		_(SEC_CODE_CHANGE_REQ);
		_(SEC_CODE_CHANGE_OK_RESP);
		_(SEC_CODE_CHANGE_FAIL_RESP);
		_(SEC_CODE_VERIFY_REQ);
		_(SEC_CODE_VERIFY_OK_RESP);
		_(SEC_CODE_VERIFY_FAIL_RESP);
		_(SEC_STATE_REQ);
		_(SEC_STATE_RESP);
	}

	return "SEC_<UNKNOWN>";
}

const char *sim_subblock_name(enum sim_subblock value)
{
	switch (value) {
		_(SIM_PB_INFO_REQUEST);
		_(SIM_PB_STATUS);
		_(SIM_PB_LOCATION);
		_(SIM_PB_LOCATION_SEARCH);
	}
	return "SIM_<UNKNOWN>";
}

const char *info_isi_cause_name(enum info_isi_cause value)
{
	switch (value) {
		_(INFO_OK);
		_(INFO_FAIL);
		_(INFO_NO_NUMBER);
		_(INFO_NOT_SUPPORTED);
	}
	return "INFO_<UNKNOWN>";
}

const char *info_message_id_name(enum info_message_id value)
{
	switch (value) {
		_(INFO_SERIAL_NUMBER_READ_REQ);
		_(INFO_SERIAL_NUMBER_READ_RESP);
		_(INFO_PP_READ_REQ);
		_(INFO_PP_READ_RESP);
		_(INFO_VERSION_READ_REQ);
		_(INFO_VERSION_READ_RESP);
		_(INFO_PRODUCT_INFO_READ_REQ);
		_(INFO_PRODUCT_INFO_READ_RESP);
	}
	return "INFO_<UNKNOWN>";
}

const char *info_subblock_name(enum info_subblock value)
{
	switch (value) {
		_(INFO_SB_MODEMSW_VERSION);
		_(INFO_SB_PRODUCT_INFO_NAME);
		_(INFO_SB_PRODUCT_INFO_MANUFACTURER);
		_(INFO_SB_SN_IMEI_PLAIN);
		_(INFO_SB_SN_IMEI_SV_TO_NET);
		_(INFO_SB_PP);
		_(INFO_SB_MCUSW_VERSION);
	}
	return "INFO_<UNKNOWN>";
}

const char *call_status_name(enum call_status value)
{
	switch (value) {
		_(CALL_STATUS_IDLE);
		_(CALL_STATUS_CREATE);
		_(CALL_STATUS_COMING);
		_(CALL_STATUS_PROCEEDING);
		_(CALL_STATUS_MO_ALERTING);
		_(CALL_STATUS_MT_ALERTING);
		_(CALL_STATUS_WAITING);
		_(CALL_STATUS_ANSWERED);
		_(CALL_STATUS_ACTIVE);
		_(CALL_STATUS_MO_RELEASE);
		_(CALL_STATUS_MT_RELEASE);
		_(CALL_STATUS_HOLD_INITIATED);
		_(CALL_STATUS_HOLD);
		_(CALL_STATUS_RETRIEVE_INITIATED);
		_(CALL_STATUS_RECONNECT_PENDING);
		_(CALL_STATUS_TERMINATED);
		_(CALL_STATUS_SWAP_INITIATED);
	}
	return "CALL_<UNKNOWN>";
}

char const *call_message_id_name(enum call_message_id value)
{
	switch (value) {
		_(CALL_CREATE_REQ);
		_(CALL_CREATE_RESP);
		_(CALL_COMING_IND);
		_(CALL_MO_ALERT_IND);
		_(CALL_MT_ALERT_IND);
		_(CALL_WAITING_IND);
		_(CALL_ANSWER_REQ);
		_(CALL_ANSWER_RESP);
		_(CALL_RELEASE_REQ);
		_(CALL_RELEASE_RESP);
		_(CALL_RELEASE_IND);
		_(CALL_TERMINATED_IND);
		_(CALL_STATUS_REQ);
		_(CALL_STATUS_RESP);
		_(CALL_STATUS_IND);
		_(CALL_SERVER_STATUS_IND);
		_(CALL_CONTROL_REQ);
		_(CALL_CONTROL_RESP);
		_(CALL_CONTROL_IND);
		_(CALL_MODE_SWITCH_REQ);
		_(CALL_MODE_SWITCH_RESP);
		_(CALL_MODE_SWITCH_IND);
		_(CALL_DTMF_SEND_REQ);
		_(CALL_DTMF_SEND_RESP);
		_(CALL_DTMF_STOP_REQ);
		_(CALL_DTMF_STOP_RESP);
		_(CALL_DTMF_STATUS_IND);
		_(CALL_DTMF_TONE_IND);
		_(CALL_RECONNECT_IND);
		_(CALL_PROPERTY_GET_REQ);
		_(CALL_PROPERTY_GET_RESP);
		_(CALL_PROPERTY_SET_REQ);
		_(CALL_PROPERTY_SET_RESP);
		_(CALL_PROPERTY_SET_IND);
		_(CALL_EMERGENCY_NBR_CHECK_REQ);
		_(CALL_EMERGENCY_NBR_CHECK_RESP);
		_(CALL_EMERGENCY_NBR_GET_REQ);
		_(CALL_EMERGENCY_NBR_GET_RESP);
		_(CALL_EMERGENCY_NBR_MODIFY_REQ);
		_(CALL_EMERGENCY_NBR_MODIFY_RESP);
		_(CALL_GSM_NOTIFICATION_IND);
		_(CALL_GSM_USER_TO_USER_REQ);
		_(CALL_GSM_USER_TO_USER_RESP);
		_(CALL_GSM_USER_TO_USER_IND);
		_(CALL_GSM_BLACKLIST_CLEAR_REQ);
		_(CALL_GSM_BLACKLIST_CLEAR_RESP);
		_(CALL_GSM_BLACKLIST_TIMER_IND);
		_(CALL_GSM_DATA_CH_INFO_IND);
		_(CALL_GSM_CCP_GET_REQ);
		_(CALL_GSM_CCP_GET_RESP);
		_(CALL_GSM_CCP_CHECK_REQ);
		_(CALL_GSM_CCP_CHECK_RESP);
		_(CALL_GSM_COMING_REJ_IND);
		_(CALL_GSM_RAB_IND);
		_(CALL_GSM_IMMEDIATE_MODIFY_IND);
		_(CALL_CREATE_NO_SIMATK_REQ);
		_(CALL_GSM_SS_DATA_IND);
		_(CALL_TIMER_REQ);
		_(CALL_TIMER_RESP);
		_(CALL_TIMER_NTF);
		_(CALL_TIMER_IND);
		_(CALL_TIMER_RESET_REQ);
		_(CALL_TIMER_RESET_RESP);
		_(CALL_EMERGENCY_NBR_IND);
		_(CALL_SERVICE_DENIED_IND);
		_(CALL_RELEASE_END_REQ);
		_(CALL_RELEASE_END_RESP);
		_(CALL_USER_CONNECT_IND);
		_(CALL_AUDIO_CONNECT_IND);
		_(CALL_KODIAK_ALLOW_CTRL_REQ);
		_(CALL_KODIAK_ALLOW_CTRL_RESP);
		_(CALL_SERVICE_ACTIVATE_IND);
		_(CALL_SERVICE_ACTIVATE_REQ);
		_(CALL_SERVICE_ACTIVATE_RESP);
		_(CALL_SIM_ATK_IND);
		_(CALL_CONTROL_OPER_IND);
		_(CALL_TEST_CALL_STATUS_IND);
		_(CALL_SIM_ATK_INFO_IND);
		_(CALL_SECURITY_IND);
		_(CALL_MEDIA_HANDLE_REQ);
		_(CALL_MEDIA_HANDLE_RESP);
	}
	return "CALL_<UNKNOWN>";
}

char const *call_isi_cause_name(enum call_isi_cause value)
{
	switch (value) {
		_(CALL_CAUSE_NO_CAUSE);
		_(CALL_CAUSE_NO_CALL);
		_(CALL_CAUSE_TIMEOUT);
		_(CALL_CAUSE_RELEASE_BY_USER);
		_(CALL_CAUSE_BUSY_USER_REQUEST);
		_(CALL_CAUSE_ERROR_REQUEST);
		_(CALL_CAUSE_COST_LIMIT_REACHED);
		_(CALL_CAUSE_CALL_ACTIVE);
		_(CALL_CAUSE_NO_CALL_ACTIVE);
		_(CALL_CAUSE_INVALID_CALL_MODE);
		_(CALL_CAUSE_SIGNALLING_FAILURE);
		_(CALL_CAUSE_TOO_LONG_ADDRESS);
		_(CALL_CAUSE_INVALID_ADDRESS);
		_(CALL_CAUSE_EMERGENCY);
		_(CALL_CAUSE_NO_TRAFFIC_CHANNEL);
		_(CALL_CAUSE_NO_COVERAGE);
		_(CALL_CAUSE_CODE_REQUIRED);
		_(CALL_CAUSE_NOT_ALLOWED);
		_(CALL_CAUSE_NO_DTMF);
		_(CALL_CAUSE_CHANNEL_LOSS);
		_(CALL_CAUSE_FDN_NOT_OK);
		_(CALL_CAUSE_USER_TERMINATED);
		_(CALL_CAUSE_BLACKLIST_BLOCKED);
		_(CALL_CAUSE_BLACKLIST_DELAYED);
		_(CALL_CAUSE_NUMBER_NOT_FOUND);
		_(CALL_CAUSE_NUMBER_CANNOT_REMOVE);
		_(CALL_CAUSE_EMERGENCY_FAILURE);
		_(CALL_CAUSE_CS_SUSPENDED);
		_(CALL_CAUSE_DCM_DRIVE_MODE);
		_(CALL_CAUSE_MULTIMEDIA_NOT_ALLOWED);
		_(CALL_CAUSE_SIM_REJECTED);
		_(CALL_CAUSE_NO_SIM);
		_(CALL_CAUSE_SIM_LOCK_OPERATIVE);
		_(CALL_CAUSE_SIMATKCC_REJECTED);
		_(CALL_CAUSE_SIMATKCC_MODIFIED);
		_(CALL_CAUSE_DTMF_INVALID_DIGIT);
		_(CALL_CAUSE_DTMF_SEND_ONGOING);
		_(CALL_CAUSE_CS_INACTIVE);
		_(CALL_CAUSE_SECURITY_MODE);
		_(CALL_CAUSE_TRACFONE_FAILED);
		_(CALL_CAUSE_TRACFONE_WAIT_FAILED);
		_(CALL_CAUSE_TRACFONE_CONF_FAILED);
		_(CALL_CAUSE_TEMPERATURE_LIMIT);
		_(CALL_CAUSE_KODIAK_POC_FAILED);
		_(CALL_CAUSE_NOT_REGISTERED);
		_(CALL_CAUSE_CS_CALLS_ONLY);
		_(CALL_CAUSE_VOIP_CALLS_ONLY);
		_(CALL_CAUSE_LIMITED_CALL_ACTIVE);
		_(CALL_CAUSE_LIMITED_CALL_NOT_ALLOWED);
		_(CALL_CAUSE_SECURE_CALL_NOT_POSSIBLE);
		_(CALL_CAUSE_INTERCEPT);
	}
	return "CALL_<UNKNOWN>";
}

char const *call_gsm_cause_name(enum call_gsm_cause value)
{
	switch (value) {
		_(CALL_GSM_CAUSE_UNASSIGNED_NUMBER);
		_(CALL_GSM_CAUSE_NO_ROUTE);
		_(CALL_GSM_CAUSE_CH_UNACCEPTABLE);
		_(CALL_GSM_CAUSE_OPER_BARRING);
		_(CALL_GSM_CAUSE_NORMAL);
		_(CALL_GSM_CAUSE_USER_BUSY);
		_(CALL_GSM_CAUSE_NO_USER_RESPONSE);
		_(CALL_GSM_CAUSE_ALERT_NO_ANSWER);
		_(CALL_GSM_CAUSE_CALL_REJECTED);
		_(CALL_GSM_CAUSE_NUMBER_CHANGED);
		_(CALL_GSM_CAUSE_NON_SELECT_CLEAR);
		_(CALL_GSM_CAUSE_DEST_OUT_OF_ORDER);
		_(CALL_GSM_CAUSE_INVALID_NUMBER);
		_(CALL_GSM_CAUSE_FACILITY_REJECTED);
		_(CALL_GSM_CAUSE_RESP_TO_STATUS);
		_(CALL_GSM_CAUSE_NORMAL_UNSPECIFIED);
		_(CALL_GSM_CAUSE_NO_CHANNEL);
		_(CALL_GSM_CAUSE_NETW_OUT_OF_ORDER);
		_(CALL_GSM_CAUSE_TEMPORARY_FAILURE);
		_(CALL_GSM_CAUSE_CONGESTION);
		_(CALL_GSM_CAUSE_ACCESS_INFO_DISC);
		_(CALL_GSM_CAUSE_CHANNEL_NA);
		_(CALL_GSM_CAUSE_RESOURCES_NA);
		_(CALL_GSM_CAUSE_QOS_NA);
		_(CALL_GSM_CAUSE_FACILITY_UNSUBS);
		_(CALL_GSM_CAUSE_COMING_BARRED_CUG);
		_(CALL_GSM_CAUSE_BC_UNAUTHORIZED);
		_(CALL_GSM_CAUSE_BC_NA);
		_(CALL_GSM_CAUSE_SERVICE_NA);
		_(CALL_GSM_CAUSE_BEARER_NOT_IMPL);
		_(CALL_GSM_CAUSE_ACM_MAX);
		_(CALL_GSM_CAUSE_FACILITY_NOT_IMPL);
		_(CALL_GSM_CAUSE_ONLY_RDI_BC);
		_(CALL_GSM_CAUSE_SERVICE_NOT_IMPL);
		_(CALL_GSM_CAUSE_INVALID_TI);
		_(CALL_GSM_CAUSE_NOT_IN_CUG);
		_(CALL_GSM_CAUSE_INCOMPATIBLE_DEST);
		_(CALL_GSM_CAUSE_INV_TRANS_NET_SEL);
		_(CALL_GSM_CAUSE_SEMANTICAL_ERR);
		_(CALL_GSM_CAUSE_INVALID_MANDATORY);
		_(CALL_GSM_CAUSE_MSG_TYPE_INEXIST);
		_(CALL_GSM_CAUSE_MSG_TYPE_INCOMPAT);
		_(CALL_GSM_CAUSE_IE_NON_EXISTENT);
		_(CALL_GSM_CAUSE_COND_IE_ERROR);
		_(CALL_GSM_CAUSE_MSG_INCOMPATIBLE);
		_(CALL_GSM_CAUSE_TIMER_EXPIRY);
		_(CALL_GSM_CAUSE_PROTOCOL_ERROR);
		_(CALL_GSM_CAUSE_INTERWORKING);
	}
	return "CALL_<UNKNOWN>";
}

const char *net_gsm_cause_name(enum net_gsm_cause value)
{
	switch (value) {
		_(NET_GSM_IMSI_UNKNOWN_IN_HLR);
		_(NET_GSM_ILLEGAL_MS);
		_(NET_GSM_IMSI_UNKNOWN_IN_VLR);
		_(NET_GSM_IMEI_NOT_ACCEPTED);
		_(NET_GSM_ILLEGAL_ME);
		_(NET_GSM_GPRS_SERVICES_NOT_ALLOWED);
		_(NET_GSM_GPRS_AND_NON_GPRS_NA);
		_(NET_GSM_MS_ID_CANNOT_BE_DERIVED);
		_(NET_GSM_IMPLICITLY_DETACHED);
		_(NET_GSM_PLMN_NOT_ALLOWED);
		_(NET_GSM_LA_NOT_ALLOWED);
		_(NET_GSM_ROAMING_NOT_IN_THIS_LA);
		_(NET_GSM_GPRS_SERV_NA_IN_THIS_PLMN);
		_(NET_GSM_NO_SUITABLE_CELLS_IN_LA);
		_(NET_GSM_MSC_TEMP_NOT_REACHABLE);
		_(NET_GSM_NETWORK_FAILURE);
		_(NET_GSM_MAC_FAILURE);
		_(NET_GSM_SYNCH_FAILURE);
		_(NET_GSM_CONGESTION);
		_(NET_GSM_AUTH_UNACCEPTABLE);
		_(NET_GSM_SERV_OPT_NOT_SUPPORTED);
		_(NET_GSM_SERV_OPT_NOT_SUBSCRIBED);
		_(NET_GSM_SERV_TEMP_OUT_OF_ORDER);
		_(NET_GSM_RETRY_ENTRY_NEW_CELL_LOW);
		_(NET_GSM_RETRY_ENTRY_NEW_CELL_HIGH);
		_(NET_GSM_SEMANTICALLY_INCORRECT);
		_(NET_GSM_INVALID_MANDATORY_INFO);
		_(NET_GSM_MSG_TYPE_NONEXISTENT);
		_(NET_GSM_CONDITIONAL_IE_ERROR);
		_(NET_GSM_MSG_TYPE_WRONG_STATE);
		_(NET_GSM_PROTOCOL_ERROR_UNSPECIFIED);
	}
	return "NET_<UNKNOWN>";
}

const char *net_isi_cause_name(enum net_isi_cause value)
{
	switch (value) {
		_(NET_CAUSE_OK);
		_(NET_CAUSE_COMMUNICATION_ERROR);
		_(NET_CAUSE_INVALID_PARAMETER);
		_(NET_CAUSE_NO_SIM);
		_(NET_CAUSE_SIM_NOT_YET_READY);
		_(NET_CAUSE_NET_NOT_FOUND);
		_(NET_CAUSE_REQUEST_NOT_ALLOWED);
		_(NET_CAUSE_CALL_ACTIVE);
		_(NET_CAUSE_SERVER_BUSY);
		_(NET_CAUSE_SECURITY_CODE_REQUIRED);
		_(NET_CAUSE_NOTHING_TO_CANCEL);
		_(NET_CAUSE_UNABLE_TO_CANCEL);
		_(NET_CAUSE_NETWORK_FORBIDDEN);
		_(NET_CAUSE_REQUEST_REJECTED);
		_(NET_CAUSE_CS_NOT_SUPPORTED);
		_(NET_CAUSE_PAR_INFO_NOT_AVAILABLE);
		_(NET_CAUSE_NOT_DONE);
		_(NET_CAUSE_NO_SELECTED_NETWORK);
		_(NET_CAUSE_REQUEST_INTERRUPTED);
		_(NET_CAUSE_TOO_BIG_INDEX);
		_(NET_CAUSE_MEMORY_FULL);
		_(NET_CAUSE_SERVICE_NOT_ALLOWED);
		_(NET_CAUSE_NOT_SUPPORTED_IN_TECH);
	}
	return "NET_<UNKNOWN>";
}

const char *net_status_name(enum net_reg_status value)
{
	switch (value) {
		_(NET_REG_STATUS_HOME);
		_(NET_REG_STATUS_ROAM);
		_(NET_REG_STATUS_ROAM_BLINK);
		_(NET_REG_STATUS_NOSERV);
		_(NET_REG_STATUS_NOSERV_SEARCHING);
		_(NET_REG_STATUS_NOSERV_NOTSEARCHING);
		_(NET_REG_STATUS_NOSERV_NOSIM);
		_(NET_REG_STATUS_POWER_OFF);
		_(NET_REG_STATUS_NSPS);
		_(NET_REG_STATUS_NSPS_NO_COVERAGE);
		_(NET_REG_STATUS_NOSERV_SIM_REJECTED_BY_NW);
	}
	return "NET_<UNKNOWN>";
}

const char *net_message_id_name(enum net_message_id value)
{
	switch (value) {
		_(NET_MODEM_REG_STATUS_GET_REQ);
		_(NET_MODEM_REG_STATUS_GET_RESP);
		_(NET_MODEM_REG_STATUS_IND);
		_(NET_MODEM_AVAILABLE_GET_REQ);
		_(NET_MODEM_AVAILABLE_GET_RESP);
		_(NET_SET_REQ);
		_(NET_SET_RESP);
		_(NET_RSSI_GET_REQ);
		_(NET_RSSI_GET_RESP);
		_(NET_CS_STATE_IND);
		_(NET_RSSI_IND);
		_(NET_CIPHERING_IND);
		_(NET_TIME_IND);
		_(NET_CHANNEL_INFO_IND);
		_(NET_RAT_IND);
		_(NET_RAT_REQ);
		_(NET_RAT_RESP);
		_(NET_CS_STATE_REQ);
		_(NET_CS_STATE_RESP);
		_(NET_CELL_INFO_GET_REQ);
		_(NET_CELL_INFO_GET_RESP);
		_(NET_CELL_INFO_IND);
		_(NET_NITZ_NAME_IND);
		_(NET_NW_ACCESS_CONF_REQ);
		_(NET_NW_ACCESS_CONF_RESP);
		_(NET_REG_STATUS_GET_REQ);
		_(NET_REG_STATUS_GET_RESP);
		_(NET_REG_STATUS_IND);
		_(NET_AVAILABLE_GET_REQ);
		_(NET_AVAILABLE_GET_RESP);
		_(NET_OPER_NAME_READ_REQ);
		_(NET_OPER_NAME_READ_RESP);
		_(NET_OLD_OPER_NAME_READ_REQ);
		_(NET_OLD_OPER_NAME_READ_RESP);
	}
	return "NET_<UNKNOWN>";
}

const char *net_subblock_name(enum net_subblock value)
{
	switch (value) {
		_(NET_REG_INFO_COMMON);
		_(NET_MODEM_AVAIL_NETWORK_INFO_COMMON);
		_(NET_OPERATOR_INFO_COMMON);
		_(NET_RSSI_CURRENT);
		_(NET_GSM_REG_INFO);
		_(NET_DETAILED_NETWORK_INFO);
		_(NET_GSM_OPERATOR_INFO);
		_(NET_TIME_INFO);
		_(NET_GSM_BAND_INFO);
		_(NET_RAT_INFO);
		_(NET_GSM_CELL_INFO);
		_(NET_WCDMA_CELL_INFO);
		_(NET_FULL_NITZ_NAME);
		_(NET_SHORT_NITZ_NAME);
		_(NET_REGISTRATION_CONF_INFO);
		_(NET_ROAMING_CONF_INFO);
		_(NET_REGISTRATION_CONF1_INFO);
		_(NET_ROAMING_CONF1_INFO);
		_(NET_AVAIL_NETWORK_INFO_COMMON);
		_(NET_OPER_NAME_INFO);
	}
	return "NET_<UNKNOWN>";
}

const char *gss_message_id_name(enum gss_message_id value)
{
	switch (value) {
		_(GSS_CS_SERVICE_REQ);
		_(GSS_CS_SERVICE_RESP);
		_(GSS_CS_SERVICE_FAIL_RESP);
	}
	return "GSS_<UNKNOWN>";
}

const char *gss_subblock_name(enum gss_subblock value)
{
	switch (value) {
		_(GSS_RAT_INFO);
	}
	return "GSS_<UNKNOWN>";
}

const char *gpds_message_id_name(enum gpds_message_id value)
{
	switch (value) {
		_(GPDS_LL_CONFIGURE_REQ);
		_(GPDS_LL_CONFIGURE_RESP);
		_(GPDS_CONTEXT_ID_CREATE_REQ);
		_(GPDS_CONTEXT_ID_CREATE_RESP);
		_(GPDS_CONTEXT_ID_CREATE_IND);
		_(GPDS_CONTEXT_ID_DELETE_IND);
		_(GPDS_CONTEXT_CONFIGURE_REQ);
		_(GPDS_CONTEXT_CONFIGURE_RESP);
		_(GPDS_CONTEXT_ACTIVATE_REQ);
		_(GPDS_CONTEXT_ACTIVATE_RESP);
		_(GPDS_CONTEXT_ACTIVATE_IND);
		_(GPDS_CONTEXT_DEACTIVATE_REQ);
		_(GPDS_CONTEXT_DEACTIVATE_RESP);
		_(GPDS_CONTEXT_DEACTIVATE_IND);
		_(GPDS_CONTEXT_MWI_ACT_REQUEST_IND);
		_(GPDS_CONTEXT_NWI_ACT_REJECT_REQ);
		_(GPDS_CONTEXT_NWI_ACT_REJECT_RESP);
		_(GPDS_CONFIGURE_REQ);
		_(GPDS_CONFIGURE_RESP);
		_(GPDS_ATTACH_REQ);
		_(GPDS_ATTACH_RESP);
		_(GPDS_ATTACH_IND);
		_(GPDS_DETACH_REQ);
		_(GPDS_DETACH_RESP);
		_(GPDS_DETACH_IND);
		_(GPDS_STATUS_REQ);
		_(GPDS_STATUS_RESP);
		_(GPDS_SMS_PDU_SEND_REQ);
		_(GPDS_SMS_PDU_SEND_RESP);
		_(GPDS_SMS_PDU_RECEIVE_IND);
		_(GPDS_TRANSFER_STATUS_IND);
		_(GPDS_CONTEXT_ACTIVATE_FAIL_IND);
		_(GPDS_LL_BIND_REQ);
		_(GPDS_LL_BIND_RESP);
		_(GPDS_CONTEXT_STATUS_REQ);
		_(GPDS_CONTEXT_STATUS_RESP);
		_(GPDS_CONTEXT_STATUS_IND);
		_(GPDS_CONTEXT_ACTIVATING_IND);
		_(GPDS_CONTEXT_MODIFY_REQ);
		_(GPDS_CONTEXT_MODIFY_RESP);
		_(GPDS_CONTEXT_MODIFY_IND);
		_(GPDS_ATTACH_FAIL_IND);
		_(GPDS_CONTEXT_DEACTIVATING_IND);
		_(GPDS_CONFIGURATION_INFO_REQ);
		_(GPDS_CONFIGURATION_INFO_RESP);
		_(GPDS_CONFIGURATION_INFO_IND);
		_(GPDS_CONTEXT_AUTH_REQ);
		_(GPDS_CONTEXT_AUTH_RESP);
		_(GPDS_TEST_MODE_REQ);
		_(GPDS_TEST_MODE_RESP);
		_(GPDS_RADIO_ACTIVITY_IND);
		_(GPDS_FORCED_READY_STATE_REQ);
		_(GPDS_FORCED_READY_STATE_RESP);
		_(GPDS_CONTEXTS_CLEAR_REQ);
		_(GPDS_CONTEXTS_CLEAR_RESP);
		_(GPDS_MBMS_SERVICE_SELECTION_REQ);
		_(GPDS_MBMS_SERVICE_SELECTION_RESP);
		_(GPDS_MBMS_STATUS_IND);
		_(GPDS_MBMS_CONTEXT_CREATE_REQ);
		_(GPDS_MBMS_CONTEXT_CREATE_RESP);
		_(GPDS_MBMS_CONTEXT_ACTIVATE_REQ);
		_(GPDS_MBMS_CONTEXT_ACTIVATE_RESP);
		_(GPDS_MBMS_CONTEXT_DELETE_REQ);
		_(GPDS_MBMS_CONTEXT_DELETE_RESP);
		_(GPDS_MBMS_CONTEXT_DELETE_IND);
		_(GPDS_MBMS_SERVICE_SELECTION_IND);
		_(GPDS_MBMS_SERVICE_AVAILABLE_IND);
		_(GPDS_TEST_REQ);
		_(GPDS_TEST_RESP);
	}
	return "GPSD_<UNKNOWN>";
}

const char *gpds_subblock_name(enum gpds_subblock value)
{
	switch (value) {
		_(GPDS_COMP_INFO);
		_(GPDS_QOS_REQ_INFO);
		_(GPDS_QOS_MIN_INFO);
		_(GPDS_QOS_NEG_INFO);
		_(GPDS_PDP_ADDRESS_INFO);
		_(GPDS_APN_INFO);
		_(GPDS_QOS99_REQ_INFO);
		_(GPDS_QOS99_MIN_INFO);
		_(GPDS_QOS99_NEG_INFO);
		_(GPDS_TFT_INFO);
		_(GPDS_TFT_FILTER_INFO);
		_(GPDS_USER_NAME_INFO);
		_(GPDS_PASSWORD_INFO);
		_(GPDS_PDNS_ADDRESS_INFO);
		_(GPDS_SDNS_ADDRESS_INFO);
		_(GPDS_CHALLENGE_INFO);
		_(GPDS_DNS_ADDRESS_REQ_INFO);
	}
	return "GPDS_<UNKNOWN>";
}

const char *gpds_status_name(enum gpds_status value)
{
	switch (value) {
		_(GPDS_ERROR);
		_(GPDS_OK);
		_(GPDS_FAIL);
	}
	return "GPDS_<UNKNOWN>";
}

const char *gpds_isi_cause_name(enum gpds_isi_cause value)
{
	switch (value) {
		_(GPDS_CAUSE_UNKNOWN);
		_(GPDS_CAUSE_IMSI);
		_(GPDS_CAUSE_MS_ILLEGAL);
		_(GPDS_CAUSE_ME_ILLEGAL);
		_(GPDS_CAUSE_GPRS_NOT_ALLOWED);
		_(GPDS_NOT_ALLOWED);
		_(GPDS_CAUSE_MS_IDENTITY);
		_(GPDS_CAUSE_DETACH);
		_(GPDS_PLMN_NOT_ALLOWED);
		_(GPDS_LA_NOT_ALLOWED);
		_(GPDS_ROAMING_NOT_ALLOWED);
		_(GPDS_CAUSE_GPRS_NOT_ALLOWED_IN_PLMN);
		_(GPDS_CAUSE_MSC_NOT_REACH);
		_(GPDS_CAUSE_PLMN_FAIL);
		_(GPDS_CAUSE_NETWORK_CONGESTION);
		_(GPDS_CAUSE_MBMS_BEARER_CAPABILITY_INSUFFICIENT);
		_(GPDS_CAUSE_LLC_SNDCP_FAILURE);
		_(GPDS_CAUSE_RESOURCE_INSUFF);
		_(GPDS_CAUSE_APN);
		_(GPDS_CAUSE_PDP_UNKNOWN);
		_(GPDS_CAUSE_AUTHENTICATION);
		_(GPDS_CAUSE_ACT_REJECT_GGSN);
		_(GPDS_CAUSE_ACT_REJECT);
		_(GPDS_CAUSE_SERV_OPT_NOT_SUPPORTED);
		_(GPDS_CAUSE_SERV_OPT_NOT_SUBSCRIBED);
		_(GPDS_CAUSE_SERV_OPT_OUT_OF_ORDER);
		_(GPDS_CAUSE_NSAPI_ALREADY_USED);
		_(GPDS_CAUSE_DEACT_REGULAR);
		_(GPDS_CAUSE_QOS);
		_(GPDS_CAUSE_NETWORK_FAIL);
		_(GPDS_CAUSE_REACTIVATION_REQ);
		_(GPDS_CAUSE_FEAT_NOT_SUPPORTED);
		_(GPDS_CAUSE_TFT_SEMANTIC_ERROR);
		_(GPDS_CAUSE_TFT_SYNTAX_ERROR);
		_(GPDS_CAUSE_CONTEXT_UNKNOWN);
		_(GPDS_CAUSE_FILTER_SEMANTIC_ERROR);
		_(GPDS_CAUSE_FILTER_SYNTAX_ERROR);
		_(GPDS_CAUSE_CONT_WITHOUT_TFT);
		_(GPDS_CAUSE_MULTICAST_MEMBERSHIP_TIMEOUT);
		_(GPDS_CAUSE_INVALID_MANDATORY_INFO);
		_(GPDS_CAUSE_MSG_TYPE_NON_EXISTENTOR_NOT_IMPLTD);
		_(GPDS_CAUSE_MSG_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE);
		_(GPDS_CAUSE_IE_NON_EXISTENT_OR_NOT_IMPLEMENTED);
		_(GPDS_CAUSE_CONDITIONAL_IE_ERROR);
		_(GPDS_CUASEMSG_NOT_COMPATIBLE_WITH_PROTOCOL_STATE);
		_(GPDS_CAUSE_UNSPECIFIED);
		_(GPDS_CAUSE_APN_INCOMPATIBLE_WITH_CURR_CTXT);
		_(GPDS_CAUSE_FDN);
		_(GPDS_CAUSE_USER_ABORT);
		_(GPDS_CAUSE_CS_INACTIVE);
		_(GPDS_CAUSE_CSD_OVERRIDE);
		_(GPDS_CAUSE_APN_CONTROL);
		_(GPDS_CAUSE_CALL_CONTROL);
		_(GPDS_CAUSE_TEMPERATURE_LIMIT);
		_(GPDS_CAUSE_RETRY_COUNTER_EXPIRED);
		_(GPDS_CAUSE_NO_CONNECTION);
		_(GPDS_CAUSE_DETACHED);
		_(GPDS_CAUSE_NO_SERVICE_POWER_SAVE);
		_(GPDS_CAUSE_SIM_REMOVED);
		_(GPDS_CAUSE_POWER_OFF);
		_(GPDS_CAUSE_LAI_FORBIDDEN_NATIONAL_ROAM_LIST);
		_(GPDS_CAUSE_LAI_FORBIDDEN_REG_PROVISION_LIST);
		_(GPDS_CAUSE_ACCESS_BARRED);
		_(GPDS_CAUSE_FATAL_FAILURE);
		_(GPDS_CAUSE_AUT_FAILURE);
	}
	return "GPDS_<UNKNOWN>";
}

const char *gpds_transfer_status_name(enum gpds_transfer_status value)
{
	switch (value) {
		_(GPDS_TRANSFER_NOT_AVAIL);
		_(GPDS_TRANSFER_AVAIL);
	}
	return "GPDS_<UNKNOWN>";
}

const char *gpds_transfer_cause_name(enum gpds_transfer_cause value)
{
	switch (value) {
		_(GPDS_TRANSFER_CAUSE_ATTACHED);
		_(GPDS_TRANSFER_CAUSE_DETACHED);
		_(GPDS_TRANSFER_CAUSE_RESUMED);
		_(GPDS_TRANSFER_CAUSE_SUSPENDED_NO_COVERAGE);
		_(GPDS_TRANSFER_CAUSE_SUSPENDED_CALL_SMS);
		_(GPDS_TRANSFER_CAUSE_SUSPENDED_CALL);
		_(GPDS_TRANSFER_CAUSE_SUSPENDED_RAU);
		_(GPDS_TRANSFER_CAUSE_SUSPENDED_LU);
		_(GPDS_TRANSFER_CAUSE_DSAC_RESTRICTION);
	}
	return "GPDS_<UNKNOWN>";
}

#undef _

static void hex_dump(const char *resname, uint8_t res, const char *name,
			uint8_t id, uint8_t utid, const uint8_t m[], size_t len)
{
	char hex[3 * 16 + 1];
	char ascii[16 + 1];
	size_t i, j, k;

	ofono_debug("%s (0x%02X): %s [id=0x%02X utid=0x%02X len=%zu]:",
			resname, res, name, id, utid, len);

	strcpy(hex, ""), j = 0;
	strcpy(ascii, "."), k = 1;

	for (i = 0; i < len; i++) {
		sprintf(hex + j, " %02X", m[i]), j += 3;
		ascii[k++] = g_ascii_isgraph(m[i]) ? m[i] : '.';

		if ((j & 48) == 48) {
			ofono_debug("    *%-48s : %.*s", hex, (int) k, ascii);
			j = 0, k = 0;
		}
	}

	if (j)
		ofono_debug("    *%-48s : %.*s", hex, (int) k, ascii);
}

static const char *res_to_name(uint8_t res, uint8_t id)
{
	if (id == COMMON_MESSAGE)
		return "COMMON_MESSAGE";

	switch (res) {
	case PN_MODEM_NETWORK:
	case PN_NETWORK:
		return net_message_id_name(id);
	case PN_PHONE_INFO:
	case PN_MODEM_INFO:
	case PN_EPOC_INFO:
		return info_message_id_name(id);
	case PN_SS:
		return ss_message_id_name(id);
	case PN_MODEM_CALL:
	case PN_CALL:
		return call_message_id_name(id);
	case PN_SECURITY:
		return sec_message_id_name(id);
	case PN_SMS:
		return sms_message_id_name(id);
	case PN_SIM:
		return sim_message_id_name(id);
	case PN_MTC:
		return mtc_message_id_name(id);
	case PN_GSS:
		return gss_message_id_name(id);
	case PN_GPDS:
		return gpds_message_id_name(id);
	case PN_UICC:
		return uicc_message_id_name(id);
	}
	return "UNKNOWN";
}

void isi_trace(const GIsiMessage *msg, void *data)
{
	uint8_t id = g_isi_msg_id(msg);
	uint8_t res = g_isi_msg_resource(msg);
	const char *resname = pn_resource_name(res);
	const char *name = res_to_name(res, id);
	uint8_t const *dump = g_isi_msg_data(msg);

	hex_dump(resname, res, name, id, g_isi_msg_utid(msg),
			dump - 2, g_isi_msg_data_len(msg) + 2);
}
